using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;

namespace Facebook.Web.Fbml
{
    [Designer(typeof(Design.SuccessDesigner))]
    public class Success : Control
    {
        private string message;

        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        private string text;

        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        public void ClearMessage()
        {
            SetMessage(string.Empty, string.Empty);
        }

        public void SetMessage(string message)
        {
            SetMessage(message, string.Empty);
        }

        public void SetMessage(string message, string text)
        {
            this.Message = message;
            this.Text = text;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(message))
                return;
            if (string.IsNullOrEmpty(text))
            {
                // simple message
                writer.Write("<fb:success");
                writer.WriteAttribute("message", message);
                writer.Write("/>");
            }
            else
            {
                // message
                writer.RenderBeginTag("fb:success");
                writer.RenderBeginTag("fb:message");
                writer.Write(message);
                writer.RenderEndTag();
                writer.Write(text);
                writer.RenderEndTag();
            }
        }
    }
}
